using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.Unity.Behaviour;
using JetBrains.Annotations;

namespace Session
{
    public abstract class SessionHCoreMonoBehaviour<T> : HCoreMonoBehaviour where T : ISession
    {
        [Autowired] private SessionService aSessionService;
        [CanBeNull] protected T Session;

        protected override void Awake()
        {
            base.Awake();
            aSessionService.AddNewGameStartBeforeEvent(session =>
            {
                Session = OnSetSession(session);
                OnPostSetSession();
            });
        }

        protected virtual T OnSetSession(ISession session)
        {
            return (T)session;
        }

        protected virtual void OnPostSetSession()
        {
        }
    }

    public abstract class SessionHCoreMonoBehaviour : SessionHCoreMonoBehaviour<ISession>
    {
    }
}